package com.github.dengmin.mysql.mapper;

import com.github.dengmin.mysql.model.DatabaseConnection;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author dengmin
 * @Created 2020/6/19 22:43
 */
public class ConnectionRowMapper implements RowMapper<DatabaseConnection> {
    private static final long serialVersionUID = 1L;

    @Override
    public DatabaseConnection mapRow(ResultSet resultSet, int i) throws SQLException {
        DatabaseConnection connection = new DatabaseConnection();
        connection.setId(resultSet.getInt("id"));
        connection.setName(resultSet.getString("name"));
        connection.setHost(resultSet.getString("host"));
        connection.setPort(resultSet.getInt("port"));
        connection.setUsername(resultSet.getString("username"));
        connection.setPassword(resultSet.getString("password"));
        connection.setDbName(resultSet.getString("dbName"));
        return connection;
    }
}
